Skip to content

Conversation

@JacksonWeber
Copy link
Contributor

@JacksonWeber JacksonWeber commented Oct 7, 2025

Which problem is this PR solving?

This pull request introduces advanced logger configuration capabilities to the OpenTelemetry JS SDK Logs package. The main feature is the new LoggerConfigurator API, which allows users to filter logs by minimum severity, trace sampling status, and to configure loggers individually using pattern matching. These changes improve flexibility and control over log processing and exporting.

Logger configuration and filtering features

  • Added the LoggerConfigurator API, enabling users to define per-logger configuration for severity filtering, trace-based filtering, and logger disabling, with pattern matching for logger names. (experimental/packages/sdk-logs/src/config/LoggerConfigurators.ts, experimental/packages/sdk-logs/src/types.ts, experimental/packages/sdk-logs/src/LoggerProvider.ts, experimental/packages/sdk-logs/src/internal/LoggerProviderSharedState.ts) [1] [2] [3] [4] [5] [6]
  • Updated the Logger class to apply minimum severity and trace-based filtering before emitting log records, dropping logs that don't meet the configured criteria. (experimental/packages/sdk-logs/src/Logger.ts) [1] [2]

Documentation and API updates

  • Expanded the README.md with detailed documentation and usage examples for the new logger configuration features, including severity and trace-based filtering and per-logger configuration patterns. (experimental/packages/sdk-logs/README.md)
  • Updated type exports and API surface to include LoggerConfig, LoggerConfigurator, and createLoggerConfigurator. (experimental/packages/sdk-logs/src/index.ts) [1] [2]

Changelog and test updates

  • Added a changelog entry for the new loggerConfigurator feature. (experimental/CHANGELOG.md)
  • Updated and expanded tests to cover the new logger configuration and filtering logic. (experimental/packages/sdk-logs/test/common/Logger.test.ts)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit tests for each type of filtering added

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@JacksonWeber JacksonWeber requested a review from a team as a code owner October 7, 2025 02:12
@codecov
Copy link

codecov bot commented Oct 7, 2025

Codecov Report

❌ Patch coverage is 98.18182% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.41%. Comparing base (bca04fd) to head (6e9324b).

Files with missing lines Patch % Lines
...ackages/sdk-logs/src/config/LoggerConfigurators.ts 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5991      +/-   ##
==========================================
+ Coverage   95.40%   95.41%   +0.01%     
==========================================
  Files         317      318       +1     
  Lines        9392     9444      +52     
  Branches     2167     2183      +16     
==========================================
+ Hits         8960     9011      +51     
- Misses        432      433       +1     
Files with missing lines Coverage Δ
experimental/packages/sdk-logs/src/Logger.ts 100.00% <100.00%> (ø)
...perimental/packages/sdk-logs/src/LoggerProvider.ts 100.00% <100.00%> (ø)
...sdk-logs/src/internal/LoggerProviderSharedState.ts 100.00% <100.00%> (ø)
...ackages/sdk-logs/src/config/LoggerConfigurators.ts 95.45% <95.45%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specification: https://github.com/open-telemetry/opentelemetry-specification/blame/f31acdf68b1c886269ab39011a338a8d72dbebea/specification/logs/sdk.md#L102-L133

@JacksonWeber - please also mark all features that are marked as in-development in the spec as @experimental in the TSdoc. This way we can avoid blocking https://github.com/open-telemetry/opentelemetry-js/milestone/19

@JacksonWeber
Copy link
Contributor Author

Specification: https://github.com/open-telemetry/opentelemetry-specification/blame/f31acdf68b1c886269ab39011a338a8d72dbebea/specification/logs/sdk.md#L102-L133

@JacksonWeber - please also mark all features that are marked as in-development in the spec as @experimental in the TSdoc. This way we can avoid blocking https://github.com/open-telemetry/opentelemetry-js/milestone/19

Experimental features have been marked as such. Thanks for the feedback!

@pichlermarc pichlermarc added the spec-feature This is a request to implement a new feature which is already specified by the OTel specification label Oct 8, 2025
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, overall I'm a bit confused by this feature - the spec for it seems still a bit vague and seems to duplicate functionality from existing features. 🤔 That's not this PR's issue, I feel like it's a symptom of a spec that's not quite where we'd need it to be yet.

I suppose the value proposition for having a LoggerConfigurator is to save on allocations in the pipeline - which is important for a hot path like this. (Q: @JacksonWeber is this the motivation for working on this feature?) If that's not the goal, then we could accomplish the same thing today in the LogRecordProcessor.

Though it seems to me that the optimizing LogRecordImpl to avoid expensive operations until it's properties are first accessed, and then applying filtering in the LogRecordProcessor may be a better way to go about it without adding additional concept to the public API.

The Go SIG seems to have a similar stance: open-telemetry/opentelemetry-specification#4644

// Get logger configuration
const loggerConfig = this._sharedState.getLoggerConfig(
this.instrumentationScope
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that emit is a hot-path, I think we should optimize here wherever possible.

One thing I noticed is that the way it's implemented right now is:

Do we need the map lookup or should we just cache it in the logger? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary motivation for this feature work is just to get an implementation of trace-based log sampling and minimum severity-based log sampling implemented in a way that's easy for users to enable as part of the configuration of their LoggerProvider.

Thanks for the link to the issue in the Go repo, I'm happy to refactor this PR to avoid the creation/usage of the LoggerConfigurator and just implement these two filtering strategies in the LogRecordProcessor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pichlermarc the PR has been updated to just add a new logRecordProcessor that handles both types of filtering. Please review when you have a chance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pichlermarc per our conversation in the JS SIG today I've reverted the changes here back to following the spec (creating the logger configurator).

@JacksonWeber JacksonWeber changed the title feat(sdk-logs): Add loggerConfigurator feat(sdk-logs): Add FilteringLogRecordProcessor Oct 23, 2025
@JacksonWeber JacksonWeber force-pushed the jacksonweber/logger-sampling branch from 12fb209 to 8e25840 Compare November 13, 2025 01:36
@JacksonWeber JacksonWeber changed the title feat(sdk-logs): Add FilteringLogRecordProcessor feat(sdk-logs): Add Logger Configurator API & Trace-based + Min-Severity Filtering Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:sdk-logs spec-feature This is a request to implement a new feature which is already specified by the OTel specification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants